package com.project.controller;

import com.project.bean.UserBean;
import org.apache.catalina.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@Controller
@RequestMapping("test")
public class TestController {

    @RequestMapping("/")//客户端只需要输入IP地址和端口号就可以访问该方法
    public String testThymeleaf(HttpServletRequest req, Model model){
        System.out.println(req.getAttribute("age"));
        //绑定共享数据
        UserBean user= new UserBean("吴京打采","13609222992","1993-11-23");
        req.setAttribute("age",20);
        req.setAttribute("name",user.getName());
        model.addAttribute("phone","13802827724");
        model.addAttribute("user",new UserBean("文林挥","17775933249 ", "1996-09-11"));
        model.addAttribute("grade",88);

        req.setAttribute("list", List.of(new UserBean("张安","110","1890-09-12"),
                new UserBean("何东夏","210","1890-07-22"),
                new UserBean("乔峰","339","1990-12-13"),
                new UserBean("陆毅","0817","1840-05-17"),
                new UserBean("和尚","707079","1890-11-16")));
        model.addAttribute("totalPage",6);
        //默认是请求转发
        return "/html/index.html";
    }
}
